From d592085dc0fec023dd9f3437d4c756d402ed8c8f Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 18 Dec 2023 11:56:59 +0100
Subject: fix(pages): use dynamic imports for the table of contents

The ToCWidget relies on Javascript to display the headings. If JS is
disabled in the browser, the widget is empty. For a better UX, we
should use dynamic imports. Now, the ToC is only displayed when JS is
enabled.
---
 src/pages/thematique/[slug].tsx | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/pages/thematique/[slug].tsx')

diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx
index 56b956f..ef21fb4 100644
--- a/src/pages/thematique/[slug].tsx
+++ b/src/pages/thematique/[slug].tsx
@@ -1,6 +1,7 @@
 /* eslint-disable max-statements */
 import type { ParsedUrlQuery } from 'querystring';
 import type { GetStaticPaths, GetStaticProps } from 'next';
+import dynamic from 'next/dynamic';
 import Head from 'next/head';
 import { useRouter } from 'next/router';
 import { useIntl } from 'react-intl';
@@ -14,7 +15,6 @@ import {
   PageSidebar,
   PageBody,
   LoadingPage,
-  TocWidget,
   Spinner,
 } from '../../components';
 import {
@@ -48,6 +48,13 @@ import {
   useThematicsList,
 } from '../../utils/hooks';
 
+const Toc = dynamic(
+  async () => import('../../components').then((mod) => mod.TocWidget),
+  {
+    ssr: false,
+  }
+);
+
 export type ThematicPageProps = {
   data: {
     currentThematic: WPThematic;
@@ -152,7 +159,7 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ data }) => {
         }}
       />
       <PageSidebar>
-        <TocWidget
+        <Toc
           heading={<Heading level={2}>{messages.widgets.tocTitle}</Heading>}
           tree={[
             ...tree,
-- 
cgit v1.2.3

